package bist.believeinstep.impl;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

import bist.believeinstep.dao.ConnectionDAO;
import bist.believeinstep.dao.RestaurantHotelImageDAO;
import bist.believeinstep.domain.RestaurantHotelImage;
import bist.believeinstep.mapper.RestaurantHotelImageMapper;


public class RestaurantHotelImageTemplate implements RestaurantHotelImageDAO, ConnectionDAO{
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public void setDataSource(DataSource dataSource){
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	@Override
	public void create(RestaurantHotelImage resHotelImage){
		String query = "INSERT INTO bist_restuarant_hotel_imges ("
				+ "bist_restaurant_hotels_id, bist_images_id, created_date, modified_date, created_by, modified_by)"
				+ "VALUES(?,?,?,?,?,?)";
		try{
			jdbcTemplate.update(query, new Object[]{
					resHotelImage.getRestaurantHotelId(),
					resHotelImage.getImageId(),
					resHotelImage.getCreated(),
					resHotelImage.getModified(),
					resHotelImage.getCreatedBy(),
					resHotelImage.getModifiedBy()
			});
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	@Override
	public void update(RestaurantHotelImage resHotelImage){
		String query = "UPDATE bist_restuarant_hotel_images SET"
				+ "bist_restaurant_hotels_id = ?"
				+ "bist_images_id = ?"
				+ "created_date = ?"
				+ "modified_date = ?"
				+ "created_by = ?"
				+ "modified_by = ?";
		try{
			jdbcTemplate.update(query, new Object[]{
				resHotelImage.getRestaurantHotelId(),
				resHotelImage.getImageId(),
				resHotelImage.getCreated(),
				resHotelImage.getModified(),
				resHotelImage.getCreatedBy(),
				resHotelImage.getModifiedBy()		
			});
	}catch(Exception ex){
		ex.printStackTrace();
	}
}
	@Override
	public void delete(Integer id){
		String query = "DELETE FROM bist_restaurant_hotel_images WHERE id = ?";
		try{
			jdbcTemplate.update(query, new Object[]{id});
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	@Override
	public List<RestaurantHotelImage> list(){
		String query = "SELECT * FROM bist_restaurant_hotel_images";
		try{
			List<RestaurantHotelImage> resHotelImage = jdbcTemplate.query(query, 
					new RestaurantHotelImageMapper());
			return resHotelImage;
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
}
